package com.sy.pet.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sy.pet.commom.ResultBean;
import com.sy.pet.dto.UserDTO;
import com.sy.pet.dto.UserQueryDTO;
import com.sy.pet.service.UserService;
import com.sy.pet.vo.UserPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author: liangSY
 * @Date: 2024/9/11
 * @ClassName: AdminUserController
 * @Description: AdminUserController描述
 */
@RequestMapping("/admin/user")
@RestController
public class AdminUserController {

    @Autowired
    UserService userService;

    @PostMapping("/page")
    public ResultBean<IPage<UserPageVo>> pageOfUser(@RequestBody @Valid UserQueryDTO dto) {
        IPage<UserPageVo> users = userService.pageOfUser(dto);
        return ResultBean.success(users);
    }

    @PostMapping("/register")
    public ResultBean<String> register(@RequestBody @Valid UserDTO dto) {
        userService.register(dto);
        return ResultBean.success();
    }

    @DeleteMapping("/{id}")
    private ResultBean<String> removeUser(@PathVariable("id") String id){
        userService.remove(id);
        return ResultBean.success();
    }

    @PutMapping("/{id}")
    private ResultBean<String> editUser(@PathVariable("id") String id,@RequestBody @Valid UserDTO dto){
        userService.editUser(id,dto);
        return ResultBean.success();
    }
}
